<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="${staticServer}/inc/style/main.css" />
<link rel="stylesheet" href="${staticServer}/inc/style/page.css" />
<link rel="stylesheet" href="${staticServer}/css/struct_info.css" />
<script src="${staticServer}/inc/js/jquery.js"></script>
<script src="${staticServer}/inc/js/pageset.js"></script>
<script src="${staticServer}/inc/js/submitter.js"></script>
<script src="${staticServer}/inc/js/infopad.js?2.2"></script>
<script>
var contextPath='${contextPath}';

$(function(){
	$('#region').change(function(){
		var center_id = $("#region").val();
		if(center_id=="" || center_id==undefined){
			$("#methodMsg").html("");
			return;
		}
		$.post("${contextPath}/index/get_method.json", {
			"center_id" : center_id
		}, function(ms) {
			var list = ms.list;
			if(list!=null && list.length>0){
				var objHtml = "";
				for(var i=0;i<list.length;i++){
					objHtml += '<a title="'+list[i].bank_id+'" id="'+list[i].id+'" onclick="delMethod('+list[i].id+')">'+list[i].name+'</a>';
				}
				$("#methodMsg").html(objHtml+"(单击可删除)");
			}else{
				$("#methodMsg").html("");
			}
		});
	});
});

var addMethod = function(){
	var center_id = $("#region").val();
	var name = $("#name").val();
	var bank_id = $("#bank_id").val();
	if(center_id==""){
		infopad.err("请选择中心!");
		return;
	}
	if(name==""){
		infopad.err("请填写新增的支付名称!");
		return;
	}
	
	$.post("${contextPath}/index/add_method_go.json", {
			"center_id" : center_id,
			"name" : name,
			"bank_id":bank_id
		}, function(ms) {
		    var msg = ms.msg;
		    if(msg=="1"){
		    	$("#methodMsg").append('<a title="'+bank_id+'" id="'+ms.id+'" onclick="delMethod('+ms.id+')">'+name+'</a>');
				infopad.msg("添加成功！");
				$("#name").val("");
				$("#bank_id").val("");
		    }else if(msg=="0"){
		    	infopad.err("该支付名称已存在！");
		    }
			
	});
};

var delMethod = function(id){
	if(confirm("确定删除？删除后无法恢复。")){
		$.post("${contextPath}/index/delete_method.json", {
			"id" : id
		}, function(ms) {
			infopad.msg("删除成功！");
			$("#"+id).remove();
		});
	};
}
</script>
</head>

<body>
	<div id="home_link">
		<ul>
			<li></li>
			<li>&gt;</li>
			<li>组织架构</li>
			<li>&gt;</li>
			<li class="current">title</li>
		</ul>
	</div>

	<div id="container">
		<div id="title">添加中心支付方式</div>
		<table id="infotable">
			<tr>
				<th>办公地址</th>
				<td>
				<select id="region">
					<option value="">请选择中心</option>
					<#if offList??>
						<#list offList as list>
							<option value="${list.id}" title="${list.address}">${list.name}</option>
						</#list>
					</#if>
				</select>
				</td>
			</tr>
			<tr>
				<th>已有支付方式</th>
				<td style="height:20px;" id="methodMsg"></td>
			</tr>
			<tr>
				<th>新增支付名称</th>
				<td><input id="name" type="text" size="50" maxlength="30" /></td>
			</tr>
			<tr>
				<th>新增支付账号</th>
				<td><input id="bank_id" type="text" size="50" maxlength="30" /></td>
			</tr>
		</table>
		<div id="controlbar">
			<input type="button" class="submit" onclick="addMethod()" value="  保存  " />
		</div>
	</div>
	
</body>
</html>